package cn.layfolk.uaa.controller;


import cn.layfolk.daimao.vo.respvo.ResponseVo;
import cn.layfolk.uaa.service.OauthClientDetailsService;
import cn.layfolk.uaa.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.io.UnsupportedEncodingException;

/**
 * <p>
 * 接入客户端信息 前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2021-01-03
 */
@RestController
public class OauthClientDetailsController {

    @Autowired
    private OauthClientDetailsService oauthClientDetailsService;

    /**
     * 新增OauthClientDetail
     * @param dto
     * @return
     */
    @PostMapping("anonymous/addOauthClientDetail")
    public ResponseVo addOauthClientDetail(@RequestBody AddOauthClientDetailInDto dto) {
        return oauthClientDetailsService.addOauthClientDetail(dto);
    }

    /**
     * 解析access token信息
     * @return
     * @throws UnsupportedEncodingException
     */
    @GetMapping("getAccessInfo")
    public AccessTokenInfoDto getAccessInfo() throws UnsupportedEncodingException {
        return oauthClientDetailsService.getAccessInfo();
    }

    /**
     * 客户端模式登录
     * @param inDto
     * @return
     */
    @PostMapping("anonymous/clientModeLogin")
    public ClientModeLoginOutDto clientModeLogin(@RequestBody ClientModeLoginInDto inDto) {
        return oauthClientDetailsService.clientModeLogin(inDto);
    }

}

